package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.TransportUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * created by wangjunfu on 2021-02-24 16:00:11
 */
@Repository
public class TransportUserDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(TransportUserDao.class);

    public TransportUser insert(final TransportUser transportUser) {
        insert("TransportUser.insert", transportUser);
        return transportUser;
    }

    public Boolean updateInfoById(final TransportUser transportUser) {
        return update("TransportUser.updateInfoById", transportUser) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("TransportUser.updateInfoByQuery", query) > 0;
    }

    public TransportUser selectById(final Integer id, final Integer entId) {
        Query query = Query.noPage();
        query.put("id", id);
        query.put("entId", entId);
        return queryForObject("TransportUser.selectById", query);
    }

    public List<TransportUser> selectByQuery(final Query query) {
        return queryForList("TransportUser.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("TransportUser.countByQuery", query);
    }

    public Boolean deleteById(final Integer id, final Integer entId) {
        TransportUser transportUser = new TransportUser();
        transportUser.setDeleteFlag(1);
        transportUser.setId(id);
        transportUser.setEntId(entId);

        return update("TransportUser.updateInfoById", transportUser) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("TransportUser.deleteById", query) > 0;
    }

    //模糊搜索会员
    public List<Map<String, String>> selectSimilarUser(final Query query) {
        List<Map<String, String>> map = queryForList("TransportUser.selectSimilarUser", query);
        return map;
    }

    //以map的形式返回数据
    public List<Map<String, String>> getMapDataByQuery(final Query query, final String element) {
        return queryForList("TransportUser." + element, query);
    }
}